﻿using System.Linq;
using ClusterAwareAdmin;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ClusterAwareProperties;

namespace ClusterAwareAdminTest
{
    
    
    /// <summary>
    ///This is a test class for DiskMethodsTest and is intended
    ///to contain all DiskMethodsTest Unit Tests
    ///</summary>
    [TestClass]
    public class DiskMethodsTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        private static ClusterManagerAdmin _manager;


        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize]
        public static void ClassTestInitialize(TestContext testContext)
        {
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup]
        public static void ClassTestCleanup()
        {
        }
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize]
        public void Initialize()
        {
            _manager = new ClusterManagerAdmin
            {
                Username = SharedConsts.User,
                Password = SharedConsts.Pwd,
                Domain = SharedConsts.Domain,
                Machine = SharedConsts.Machine,
                CacheInstances = false
            };
            _manager.Connect();
        }
        //
        //Use TestCleanup to run code after each test has run
        [TestCleanup]
        public void Cleanup()
        {
            _manager.Dispose();
        }

        #endregion

        /// <summary>
        ///A test for GetDisks
        ///</summary>
        [TestMethod]
        public void GetDisksTest()
        {
            var target = new DiskMethods(_manager); 
            var actual = target.GetDisks();
            Assert.AreNotEqual(null, actual);
        }

        /// <summary>
        ///A test for GetDisk
        ///</summary>
        [TestMethod]
        public void GetDiskTest()
        {
            var target = new DiskMethods(_manager);
            foreach (var actual in target.GetDisks().Select(dsk => target.GetDisk(dsk.Name)))
            {
                Assert.AreNotEqual(null, actual);
            }
        }

        /// <summary>
        ///A test for GetAvailableDisks
        ///</summary>
        [TestMethod]
        public void GetAvailableDisksTest()
        {
            var target = new DiskMethods(_manager);
            var actual = target.GetAvailableDisks();
            Assert.AreNotEqual(null, actual);
        }

        /// <summary>
        ///A test for GetAvailableDisk
        ///</summary>
        [TestMethod]
        public void GetAvailableDiskTest()
        {
            var target = new DiskMethods(_manager);
            foreach (var actual in target.GetAvailableDisks().Select(dsk => target.GetAvailableDisk(dsk.Name)))
            {
                Assert.AreNotEqual(null, actual);
            }
        }

        /// <summary>
        ///A test for ExistDisk
        ///</summary>
        [TestMethod]
        public void ExistDiskTest()
        {
            var target = new DiskMethods(_manager);
            foreach (var actual in target.GetDisks().Select(dsk => target.GetDisk(dsk.Name)))
            {

                Assert.AreEqual(true, target.ExistDisk(actual.Name));
            }
            Assert.AreEqual(false, target.ExistDisk("notfound"));
        }

        /// <summary>
        ///A test for ExistAvailableDisk
        ///</summary>
        [TestMethod]
        public void ExistAvailableDiskTest()
        {
            var target = new DiskMethods(_manager);
            foreach (var actual in target.GetAvailableDisks().Select(dsk => target.GetAvailableDisk(dsk.Name)))
            {

                Assert.AreEqual(true, target.ExistDisk(actual.Name));
            }
            Assert.AreEqual(false, target.ExistAvailableDisk("notfound"));
        }

        /// <summary>
        ///A test for AddAvailableDiskToCluster
        ///</summary>
        [TestMethod]
        public void AddAvailableDiskToClusterTest()
        {
            if (_manager.OperationSystem == WindowsOperationSystem.Windows2003 || _manager.OperationSystem == WindowsOperationSystem.Windows2003R2)
            {
                Assert.Inconclusive("Windows 2003 not suport Method AddAvailableDisk");
            }
            //var target = new DiskMethods(_manager);
            //target.AddAvailableDiskToCluster(target.GetDisk(<put name disk>));
            Assert.Inconclusive("Put name disk to test AddAvailableDisk");
        }

        /// <summary>
        ///A test for DiskMethods Constructor
        ///</summary>
        [TestMethod]
        public void DiskMethodsConstructorTest()
        {
            new DiskMethods(_manager);
        }
    }
}
